package com.example.administrator.z.adapter;

import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.z.R;
import com.example.administrator.z.entity.NoticeData;
import com.example.administrator.z.util.PicassoUtils;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;
import java.util.zip.Inflater;

public class SchoolNoticeAdapter extends BaseAdapter {

    private LayoutInflater inflater;
    private List<NoticeData>mList;
    private Context mContext;
    private NoticeData data;
    public SchoolNoticeAdapter(Context mContext, List<NoticeData> mList) {
        this.mContext = mContext;
        this.mList = mList;
        inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);


    }
    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder = null;
        if (view == null){
            viewHolder = new ViewHolder();
            view = inflater.inflate(R.layout.adapter_notice, null);
            viewHolder.tv_title =(TextView) view.findViewById(R.id.tv_title);
            viewHolder.tv_author =(TextView) view.findViewById(R.id.tv_author);
            viewHolder.tv_time =(TextView) view.findViewById(R.id.tv_time);
            viewHolder.tv_content =(TextView) view.findViewById(R.id.tv_content);
            viewHolder.iv_img1 = (ImageView) view.findViewById(R.id.iv_img1);
            viewHolder.iv_img2 = (ImageView) view.findViewById(R.id.iv_img2);
            viewHolder.iv_img3 = (ImageView) view.findViewById(R.id.iv_img3);
            view.setTag(viewHolder);

        }else {

            viewHolder = (ViewHolder) view.getTag();
        }

        data = mList.get(position);
        viewHolder.tv_title.setText(data.getTitle());
        viewHolder.tv_author.setText(data.getAuthor());
        viewHolder.tv_time.setText(data.getTime());
        viewHolder.tv_content.setText(data.getContent());
            //加载图片
            Picasso.with(mContext).load(R.mipmap.ic_launcher).into(viewHolder.iv_img1);
        Picasso.with(mContext).load(R.mipmap.ic_launcher).into(viewHolder.iv_img2);
        Picasso.with(mContext).load(R.mipmap.ic_launcher).into(viewHolder.iv_img3);


        return view;
    }

    class  ViewHolder {

    private TextView tv_title;
    private TextView tv_author,tv_time,tv_content;
    private ImageView iv_img1,iv_img2,iv_img3;
    }
}
